/// <license>
/// Copyright (c) 2002-2008, DotNetNuke Corporation
/// All rights reserved
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
/// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
/// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
/// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
/// of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
/// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
/// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
/// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
/// DEALINGS IN THE SOFTWARE.
/// </license>

#region Using Statements

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Users;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Portals;
using DotNetNuke.UI.WebControls;
using System.Xml.Serialization;
using System.Data;
using DotNetNuke.ModuleToolkit.Common;

#endregion

namespace DotNetNuke.ModuleToolkit.Framework
{
    /// -----------------------------------------------------------------------------
    /// <summary>
    /// The VersionedEntityBase Class provides a common Base class for all Versioned
    /// DotNetNuke Entities.
    /// </summary>
    /// <history>
    /// 	[cnurse]	10/26/2007	Created
    /// </history>
    /// -----------------------------------------------------------------------------
    public class VersionedEntityBase : 
        EntityBase,
        IVersionable
    {

        #region Private Members

        private PublishedStatus _Status;
        private int _VersionNo;

        #endregion

        #region Protected Methods

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Hydrates an Entity from a DataReader representing the Entity
        /// </summary>
        /// <param name="entity">The Entity object to fill</param>
        /// <param name="source">The Data Reader containing the values to use to fill the Entity.</param>
        /// <history>
        /// 	[cnurse]	10/26/2007	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        protected override void FillInternal(IDataReader source)
        {
            Status = (PublishedStatus)Enum.Parse(typeof(PublishedStatus), Convert.ToString(Null.SetNull(source["Status"], Status)));
            VersionNo = Convert.ToInt32(Null.SetNull(source["VersionNo"], VersionNo));

            //Call base methods FillInternal method
            base.FillInternal(source);
        }

        #endregion

        #region IVersionable Members

        /// <summary>
        /// Gets whether the Entity has been deleted
        /// </summary>
        [Browsable(false)]
        public bool IsDeleted
        {
            get { return Status == PublishedStatus.Deleted; }
        }

        /// <summary>
        /// Gets whether the Entity is a draft
        /// </summary>
        [Browsable(false)]
        public bool IsDraft
        {
            get { return Status != PublishedStatus.Published && !IsDeleted; }
        }


        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets and sets the Status of the Entity
        /// </summary>
        /// <history>
        /// 	[cnurse]	10/26/2007	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        [Browsable(true), Category("Basic"), IsReadOnly(true), SortOrder(998)]
        public PublishedStatus Status
        {
            get { return _Status; }
            set { _Status = value; }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets and sets the Version No of the Article
        /// </summary>
        /// <history>
        /// 	[cnurse]	10/26/2007	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        [Browsable(true), Category("Basic"), IsReadOnly(true), SortOrder(999)]
        public int VersionNo
        {
            get { return _VersionNo; }
            set { _VersionNo = value; }
        }

        #endregion

    }
}
